﻿using StyleCop;
using StyleCop.CSharp;

namespace Jsl.StyleCop.CSharp.RefactoringRules
{
    /// <summary>
    /// A collect of rules for catching smelly code.
    /// </summary>
    [SourceAnalyzer(typeof(CsParser))]
    public class RuleAnalyzer : SourceAnalyzer
    {
        /// <summary>
        /// You shouldn't compare a Boolean value to a Boolean constant.
        /// </summary>
        public static readonly string DoNotCompareToBooleanConstant = "DoNotCompareToBooleanConstant";

        /// <summary>
        /// If you set a variable, you should use it before it is overwritten.
        /// </summary>
        public static readonly string LocalVariableAssignmentUnused = "LocalVariableAssignmentUnused";

        /// <summary>
        /// Local variables should be set where they are declared.
        /// </summary>
        public static readonly string LocalVariablesShouldBeSetWhereTheyAreDeclared = "LocalVariablesShouldBeSetWhereTheyAreDeclared";

        /// <summary>
        /// Move variable declarations to the level of their usage.
        /// </summary>
        public static readonly string MoveVariableDeclarationToUsageLevel = "MoveVariableDeclarationToUsageLevel";

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="RuleAnalyzer"/> class.
        /// </summary>
        public RuleAnalyzer()
        {
        }
        #endregion Constructors

        #region Public Methods
        /// <summary>
        /// Analyzes the document.
        /// </summary>
        /// <param name="document">The document to analyze.</param>
        public override void AnalyzeDocument(CodeDocument document)
        {
            RuleAnalyzerHelper.AnalyzeDocumentRules(
                document,
                new DoNotCompareToBooleanConstant(this));

            RuleAnalyzerHelper.AnalyzeGraphRules(
                document,
                new LocalVariableAssignmentUnused(this),
                new LocalVariablesShouldBeSetWhereTheyAreDeclared(this),
                new MoveVariableDeclarationToUsageLevel(this));
        }
        #endregion Public Methods
    }
}